{extend name='table'}

{block name="content"}
<div class="layui-tab layui-tab-card">
    <div class="layui-tab-content">
        {include file='order/order/index_search'}
        <table id="order" data-url="{:sysuri()}" data-target-search="form.form-search"></table>
    </div>
</div>
{/block}

{block name='script'}
<script>

    var maxWidth = window.innerWidth;
    var maxHeight = window.innerHeight;

    $(function () {
        // 初始化表格组件
        $('#order').layTable({
            even: true, height: 'full',
            // sort: {field: 'id', type: 'desc'},
            toolbar: '#toolbarDemo',
            cols: [[
                {checkbox: true, fixed: true},
                /** {if $super} **/
                {field: 'company_name', title: '{:lang("公司")}', minWidth: 130, align: 'center'},
                /** {/if} **/
                {field: 'platform_name', title: '{:lang("平台")}', minWidth: 120, align: 'center'},
                {field: 'warehouse_c_name', title: '{:lang("仓库名称")}', minWidth: 130, align: 'center'},
                {field: 'country', title: '{:lang("发往国家")}', minWidth: 120, align: 'center'},
                {field: 'order_no', title: '{:lang("订单编号")}', minWidth: 130, align: 'center'},
                {field: 'express_num', title: '{:lang("包裹数量")}', minWidth: 110, align: 'center'},
                {field: 'has_express_num', title: '{:lang("入库数量")}', minWidth: 110, align: 'center'},
                {field: 'create_at', title: '{:lang("添加时间")}', minWidth: 150, align: 'center'},
                {field: 'status', title: '{:lang("状态")}', minWidth: 110, align: 'center'},
                {toolbar: '#toolbar', align: 'center', width: 150, title: '{:lang("操作")}', fixed: 'right'},
            ]]
        });

        // 工具栏事件
        layui.table.on('toolbar(order)', function(obj){
            let id = obj.config.id
            let checkStatus = layui.table.checkStatus(id)
            let data = checkStatus.data
            // var othis = lay(this)

            let ids = []
            for (let i = 0; i < data.length; i++){
                ids[i] = data[i].id
            }

            switch(obj.event){
                case 'print_pick': // 打印拣货单

                    $.ajax({
                        url: '{:url("print_pick")}',
                        type: 'post',
                        dataType: "json",
                        data: {ids:ids},
                        beforeSend:(res)=>{indexload = layer.load(3, {shade: [0.1,'#fff']});},  //0.1透明度的白色背景
                        complete:(res)=>{layer.close(indexload);},
                        success: function (res) {
                            if(res.code == 1){
                                //初始化打印插件
                                hiprint.init();
                                // 打印模板
                                let json = {"panels":[{"index":0,"paperType":"A4","height":210,"width":297,"paperHeader":70.5,"paperFooter":595.2755905511812,"printElements":[{"options":{"left":1.5,"top":4.5,"height":52.5,"width":837,"title":"拣货清单","fontSize":21.75,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle"},"printElementType":{"type":"text"}},{"options":{"left":111,"top":9,"height":54,"width":238.5,"field":"order_no","testData":"OO3263773cbfbc6d8","textType":"barcode","textAlign":"center","fontSize":12,"lineHeight":12},"printElementType":{"type":"text"}},{"options":{"left":61.5,"top":36,"height":19.5,"width":48,"title":"订单号：","fontFamily":"Microsoft YaHei","textAlign":"right","textContentVerticalAlign":"middle","fontSize":11.25},"printElementType":{"type":"text"}},{"options":{"left":94.5,"top":82.5,"height":16.5,"width":136.5,"field":"user_name","fontFamily":"Microsoft YaHei","fontSize":12,"textContentVerticalAlign":"middle","borderBottom":"solid"},"printElementType":{"type":"text"}},{"options":{"left":595.5,"top":82.5,"height":15,"width":51,"title":"拣货人：","fontFamily":"Microsoft YaHei","fontSize":12,"textAlign":"right","textContentVerticalAlign":"middle"},"printElementType":{"type":"text"}},{"options":{"left":646.5,"top":82.5,"height":15,"width":120,"field":"print_name","fontFamily":"Microsoft YaHei","fontSize":10.5,"textContentVerticalAlign":"middle","borderBottom":"solid","testData":"史茹坤"},"printElementType":{"type":"text"}},{"options":{"left":39,"top":82.5,"height":16.5,"width":55.5,"title":"收件人：","fontFamily":"Microsoft YaHei","fontSize":12,"textAlign":"right","textContentVerticalAlign":"middle"},"printElementType":{"type":"text"}},{"options":{"left":94.5,"top":108,"height":16.5,"width":135,"field":"user_mobile","fontFamily":"Microsoft YaHei","fontSize":12,"textContentVerticalAlign":"middle","borderBottom":"solid"},"printElementType":{"type":"text"}},{"options":{"left":565.5,"top":108,"height":16.5,"width":81,"title":"拣货日期：","fontFamily":"Microsoft YaHei","fontSize":12,"textAlign":"right","textContentVerticalAlign":"middle"},"printElementType":{"type":"text"}},{"options":{"left":646.5,"top":108,"height":16.5,"width":120,"field":"print_time","fontFamily":"Microsoft YaHei","fontSize":12,"textContentVerticalAlign":"middle","borderBottom":"solid","testData":"2021-11-16 12:12:00"},"printElementType":{"type":"text"}},{"options":{"left":39,"top":108,"height":16.5,"width":57,"title":"电话号：","fontFamily":"Microsoft YaHei","fontSize":12,"textAlign":"right","textContentVerticalAlign":"middle"},"printElementType":{"type":"text"}},{"options":{"left":94.5,"top":133.5,"height":51,"width":672,"field":"user_address","fontFamily":"Microsoft YaHei","fontSize":12,"testData":"LaishevskLaishevskij Tatarstan Rossiya Rossiya, Respublika Tatarstan, Laishevskij rajon, selo Sokury`, ulicza Dostoevskogo, 9ij Tatarstan Rossiya Rossiya, Respublika Tatarstan, Laishevskij rajon, selo Sokury`, ulicza Dostoevskogo, 9","lineHeight":15},"printElementType":{"type":"text"}},{"options":{"left":39,"top":133.5,"height":16.5,"width":55.5,"title":"地址：","fontFamily":"Microsoft YaHei","fontSize":12,"textAlign":"right","textContentVerticalAlign":"middle"},"printElementType":{"type":"text"}},{"options":{"left":39,"top":187.5,"height":51,"width":726,"field":"orderexpress","fontFamily":"Microsoft YaHei","textAlign":"center","tableBodyRowBorder":"noBorder","tableHeaderFontWeight":"bold","columns":[[{"title":"序号","field":"no","width":50.13038363663627,"colspan":1,"rowspan":1,"checked":true,"columnId":"no"},{"title":"物流名称","field":"express_company","width":194.60828872099523,"colspan":1,"rowspan":1,"checked":true,"columnId":"location_id"},{"title":"物流单号","field":"express_no","width":284.8693582223549,"colspan":1,"rowspan":1,"checked":true,"columnId":"bar_code"},{"title":"数量","field":"num","width":93.9721654756501,"colspan":1,"rowspan":1,"checked":true,"columnId":"num"},{"title":"货位","field":"location_code","width":102.41980394436341,"colspan":1,"rowspan":1,"checked":true,"columnId":"seeding_position"}]]},"printElementType":{"title":"表格","type":"tableCustom"}},{"options":{"left":100.5,"top":238.5,"height":22.5,"width":129,"field":"goods_total_num","fontFamily":"Microsoft YaHei","fontSize":10.5,"textContentVerticalAlign":"middle","borderBottom":"solid","testData":"10"},"printElementType":{"type":"text"}},{"options":{"left":526.5,"top":238.5,"height":22.5,"width":120,"title":"清单条数：","fontFamily":"Microsoft YaHei","fontSize":12,"textAlign":"right","textContentVerticalAlign":"middle"},"printElementType":{"type":"text"}},{"options":{"left":646.5,"top":240,"height":22.5,"width":120,"field":"order_info_num","testData":"10","fontFamily":"Microsoft YaHei","fontSize":10.5,"textContentVerticalAlign":"middle","borderBottom":"solid"},"printElementType":{"type":"text"}},{"options":{"left":39,"top":238.5,"height":22.5,"width":61.5,"title":"包裹总数：","fontFamily":"Microsoft YaHei","fontSize":12,"textAlign":"right","textContentVerticalAlign":"middle"},"printElementType":{"type":"text"}}],"paperNumberLeft":811,"paperNumberTop":573,"rotate":true,"orient":2}]}

                                // 打印渲染数据
                                let jsonData = res.data.jsonData;

                                // 实例化并打印
                                var hiprintTemplate = new hiprint.PrintTemplate({ template:  json});
                                hiprintTemplate.print(jsonData);
                            }
                        }
                    });
                    break;
            };
        });

        // 单元格工具事件
        layui.table.on('tool(order)', function(obj){
            var data = obj.data; // 得到当前行数据
            var layEvent = obj.event; // 获得元素对应的 lay-event 属性值

            // 根据 lay-event 的值执行不同操作
            if(layEvent === 'print_pick_code'){ //打印拣货码
                $.ajax({
                    url: '{:url("print_pick_code")}',
                    type: 'post',
                    dataType: "json",
                    data: {id: data.id},
                    beforeSend:(res)=>{indexload = layer.load(3, {shade: [0.1,'#fff']});},  //0.1透明度的白色背景
                    complete:(res)=>{layer.close(indexload);},
                    success: function (res) {
                        if(res.code == 1){
                            //初始化打印插件
                            hiprint.init();
                            // 打印模板
                            let json = {"panels":[{"index":0,"height":100,"width":100,"paperHeader":-15,"paperFooter":283.46456692913387,"printElements":[{"options":{"left":0,"top":12,"height":9.75,"width":282,"title":"拣货标签","fontSize":12,"fontWeight":"bolder","textAlign":"center"},"printElementType":{"type":"text"}},{"options":{"left":57,"top":34.5,"height":30,"width":166.5,"field":"flag","testData":"12-1-23","fontSize":15,"fontWeight":"bold","textAlign":"center","lineHeight":19.5,"textType":"barcode"},"printElementType":{"type":"text"}},{"options":{"left":52.5,"top":87,"height":40.5,"width":216,"field":"goods_name","testData":"三合一充电线适用安卓 Type-c 苹果 手机黑色编织充电线-1条,黑色三合一充电线适用安卓 Type-c ","fontSize":9,"lineHeight":12.75},"printElementType":{"type":"longText"}},{"options":{"left":13.5,"top":87,"height":40.5,"width":39,"title":"品名：","fontSize":11.25},"printElementType":{"type":"text"}},{"options":{"left":13.5,"top":132,"height":9.75,"width":39,"title":"数量：","fontSize":11.25},"printElementType":{"type":"text"}},{"options":{"left":52.5,"top":132,"height":9.75,"width":216,"field":"num","testData":"23","fontSize":15,"fontWeight":"bold"},"printElementType":{"type":"text"}},{"options":{"left":0,"top":195,"height":9.75,"width":282,"title":"拣货单号","fontSize":12,"fontWeight":"bold","textAlign":"center"},"printElementType":{"type":"text"}},{"options":{"left":39,"top":216,"height":30,"width":204,"field":"order_no","testData":"1989667129131240769","fontSize":15,"textAlign":"center","lineHeight":19.5,"textType":"barcode"},"printElementType":{"type":"text"}},{"options":{"left":13.5,"top":151.5,"height":9.75,"width":39,"title":"货位：","fontSize":11.25},"printElementType":{"type":"text"}},{"options":{"left":52.5,"top":151.5,"height":9.75,"width":216,"field":"location_code","testData":"A12-01-12","fontSize":15,"fontWeight":"bold"},"printElementType":{"type":"text"}},{"options":{"left":13.5,"top":171,"height":9.75,"width":39,"title":"日期：","fontSize":11.25},"printElementType":{"type":"text"}},{"options":{"left":52.5,"top":171,"height":9.75,"width":216,"field":"print_time","testData":"2024-12-04 10:55:34","fontSize":10.5},"printElementType":{"type":"text"}}],"paperNumberLeft":253.5,"paperNumberTop":261,"paperNumberDisabled":true}]}

                            // 打印渲染数据
                            let jsonData = res.data.jsonData;

                            // 实例化并打印
                            var hiprintTemplate = new hiprint.PrintTemplate({ template:  json});
                            hiprintTemplate.print(jsonData);
                        }
                    }
                });
            }
        });

    });
</script>

<script type="text/html" id="toolbarDemo">
    <!--{if auth('print_pick')}-->
    <a lay-event="print_pick" class='layui-btn layui-btn-xs layui-btn-primary'>{:lang('打印拣货单')}</a>
    <!--{/if}-->
<!--    &lt;!&ndash;{if auth("add")}&ndash;&gt;-->
<!--    <button  data-modal='{:url("add")}' data-title="{:lang('添加仓库')}"  class='layui-btn layui-btn-sm layui-btn-primary'>{:lang('添加仓库')}</button>-->
<!--    &lt;!&ndash;{/if}&ndash;&gt;-->
<!--&lt;!&ndash;    {if auth("remove")}&ndash;&gt;-->
<!--    <a data-confirm="{:lang('确定要删除吗？')}" data-table-id="HouseTable" data-action="{:url('remove')}" data-rule="id#{id}" class='layui-btn layui-btn-sm layui-btn-danger'>{:lang('批量删除')}</a>-->
<!--&lt;!&ndash;    {/if}&ndash;&gt;-->
</script>

<!-- 数据操作工具条模板 -->
<script type="text/html" id="toolbar">
    <!--{if auth('info')}-->
    <a class="layui-btn layui-btn-xs layui-btn-primary" data-title="{:lang('查看')}" data-offset="['60px','200px']" data-area="['{{maxWidth-210}}px', '{{maxHeight-60}}px']"  data-modal='{:url("info")}?id={{d.id}}'>{:lang('查看')}</a>
    <!--{/if}-->
<!--    &lt;!&ndash;{if auth('edit')}&ndash;&gt;-->
<!--    <a class="layui-btn layui-btn-xs"  data-offset = "525px,240px" data-event-dbclick data-title="{:lang('编辑数据')}" data-modal='{:url("edit")}?id={{d.id}}'>{:lang('编 辑')}</a>-->
<!--    &lt;!&ndash;{/if}&ndash;&gt;-->

<!--    &lt;!&ndash;{if auth("remove")}&ndash;&gt;-->
<!--    <a class="layui-btn layui-btn-danger layui-btn-xs" data-confirm="{:lang('确定要删除数据吗?')}" data-action="{:url('remove')}" data-value="id#{{d.id}}">{:lang('删 除')}</a>-->
<!--    &lt;!&ndash;{/if}&ndash;&gt;-->

<!--    &lt;!&ndash;{if auth('print_pick')}&ndash;&gt;-->
<!--    <a lay-event="print_pick_code" class='layui-btn layui-btn-xs layui-btn-primary'>{:lang('打印拣货码')}</a>-->
<!--    &lt;!&ndash;{/if}&ndash;&gt;-->
</script>
{/block}